import axios from 'axios'
import nprogress from 'nprogress'
import 'nprogress/nprogress.css'

const http = axios.create({
    baseURL: "http://127.0.0.1:8000"
})

http.interceptors.request.use(config => {
    nprogress.start()
    let user = window.sessionStorage.getItem('user')
    if(user){
        let token = JSON.parse(user).token
        config.headers.token = token
    }
    return config
},err=>{
    console.log(err)
})

http.interceptors.response.use(response => {
    nprogress.done()
    return response.data
},err=>{
    console.log(err)
})

export default http